﻿using System.Windows;
using System.Windows.Media.Animation;
using xpds_ProductMonitor.Command;
using xpds_ProductMonitor.UserControls;
using xpds_ProductMonitor.ViewModels;
using xpds_ProductMonitor.Views;

namespace xpds_ProductMonitor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindowVM ViewModel = new MainWindowVM();

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = ViewModel;
        }

        public void ShowDetailUC()
        {
            WorkShopDetailUC workShopDetailUC = new WorkShopDetailUC();

            ViewModel.MonitorUC = workShopDetailUC;

            //动画效果(由下而上)
            ThicknessAnimation thicknessAnimation =
                new ThicknessAnimation(new Thickness(0, 50, 0, -50),
                    new Thickness(0, 0, 0, 0),
                    new TimeSpan(0, 0, 0, 400));
            //透明度
            DoubleAnimation opacityAnimation = new DoubleAnimation(0, 1, new TimeSpan(0, 0, 0, 400));

            //设置目标
            Storyboard.SetTarget(thicknessAnimation, workShopDetailUC);
            Storyboard.SetTarget(opacityAnimation, workShopDetailUC);
            //设置属性
            Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin"));
            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
            //创建storyboard
            Storyboard storyboard = new Storyboard();
            //添加动画
            storyboard.Children.Add(thicknessAnimation);
            storyboard.Children.Add(opacityAnimation);
            //开始动画
            storyboard.Begin();
        }

        /// <summary>
        /// 返回主界面
        /// </summary>
        private void GoBackMonitor()
        {
            ViewModel.MonitorUC = new MonitorUserControl();
        }

        /// <summary>
        /// 展示详情命令
        /// </summary>
        public OpCommand ShowDetailCmm
        {
            get { return new OpCommand(ShowDetailUC); }
        }

        /// <summary>
        /// 返回监控页面
        /// </summary>
        public OpCommand GoBackCmm
        {
            get
            {
                return new OpCommand(GoBackMonitor);
            }
        }



        #region 弹出配置窗口
        /// <summary>
        /// 弹出配置窗口
        /// </summary>
        private void ShowSettingWin()
        {
            //父子关系
            SettingsWin settingsWin = new SettingsWin() { Owner = this };
            settingsWin.ShowDialog();
        }

        /// <summary>
        /// 创建 弹出配置窗口 命令
        /// </summary>
        public OpCommand ShowSettingaCmm
        {
            get
            {
                return new OpCommand(ShowSettingWin);
            }
        }

        #endregion

        private void BtnMin(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }
        private void BtnMax(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else
            {
                this.WindowState = WindowState.Maximized;
            }
        }
        private void BtnClose(object sender, RoutedEventArgs e)
        {
            //关闭窗口
            //this.Close();
            //关闭进程
            System.Environment.Exit(0);
        }


    }
    
}